package cn.edu.zafu.bigdata.LiJuan.ch11;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        String host = "192.168.16.15"; // 服务端地址   //"192.168.16.16"是同学的局域网IP地址
        int port = 9999; // 服务端端口     //改成同学的端口号即可连接成功
        Socket socket = new Socket(host, port);

        InputStream input = socket.getInputStream();
        OutputStream output = socket.getOutputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        PrintWriter writer = new PrintWriter(output, true);
        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while ((line = console.readLine()) != null) {
            writer.println(line); // 发送消息到服务端
            System.out.println("服务器回复: " + reader.readLine());
            if ("exit".equalsIgnoreCase(line)) {
                break;
            }
        }

        socket.close();
    }
}